import { getUrlParam, arrayFind } from '@/utils/tools'

const region = [
  {
    id: 100,
    name: '河南',
    hasChildren: true,
    children: [
      {
        id: 101,
        name: '郑州',
        hasChildren: true,
        children: [
          {
            id: 101001,
            name: '中原区',
            hasChildren: false
          }
        ]
      },
      {
        id: 102,
        name: '安阳',
        hasChildren: false
      }
    ]
  },
  {
    id: 200,
    name: '山东',
    hasChildren: true,
    children: [
      {
        id: 201,
        name: '青岛',
        hasChildren: false
      }
    ]
  }
]
export default {
  fetchRegion(req) {
    let region_id = getUrlParam('id', req.url)
    let regionReturn = []
    if (region_id < 0) {
      regionReturn = region
    } else {
      regionReturn = arrayFind(region_id, 'id', region, 'children')
    }
    return {
      code: 1,
      msg: '',
      data: {
        region: regionReturn
      }
    }
  }
}
